package team.seekers.hula.question.questionDevelopBook.note.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.question.questionDevelopBook.note.entity.dto.NoteAddDTO;
import team.seekers.hula.question.questionDevelopBook.note.entity.dto.NoteUpdateDTO;
import team.seekers.hula.question.questionDevelopBook.note.entity.vo.NoteListVO;
import team.seekers.hula.question.questionDevelopBook.note.service.NoteService;
import team.seekers.hula.auth.service.MindUtils;
import java.util.List;

/**
 * 书籍笔记 前端控制器
 * @author hbc
 * @since 2022-11-22
 */
@Controller
@ApiResponseBody
@RequestMapping("/note")
public class NoteController {

    @Autowired
    private NoteService noteService;

    @PostMapping("/add")
    public String add(@RequestBody NoteAddDTO addDTO){
        addDTO.setUserId(MindUtils.getUserId());
        return noteService.save(addDTO);
    }

    @GetMapping("/delete")
    public void delete(@RequestParam String id){
        noteService.delete(id);
    }


    @PostMapping("/update")
    public void update(@RequestBody NoteUpdateDTO updateDTO){
        noteService.update(updateDTO);
    }

    @GetMapping("/book")
    public List<NoteListVO> get(@RequestParam String bookId){
        return noteService.queryNotesByBookId(bookId, MindUtils.getUserId());
    }

//
//    @GetMapping("/get/{FlomoId}")
//    public R get(@PathVariable("FlomoId") String flomoId){
//        return null;
//    }

    // 分页加载其他用户的笔记
    @GetMapping("/loadOthers")
    public PageResult pageOthersOrderByTime(@RequestParam long pageNow,
                             @RequestParam long pageSize,
                             @RequestParam long noteId){
        return noteService.pageOthersOrderByTime(pageNow,pageSize,noteId);
    }

}

